fn main() {
    println!("Hello, world!");
    let number: i32 = 6;

    //if的条件必须是bool类型！！！，Rust不会将非bool值转成bool值
    //
    if number % 4 == 0 {
        println!("number is divisible by 4");
    } else if number % 3 == 0 {
        println!("number is divisible by 3");
    } else if number % 2 == 0 {
        println!("number is divisible by 2");
    } else {
        println!("number is not divisible by 4, 3, or 2");
    }
    //prints number is divisible by 3

    //let 中使用if
    //if,else表达式的返回值类型必须相同！
    let condition = true;
    let number: i32 = if condition {
        5
    } else {
        6
    };

    //prints The value of number is: 5
    println!("The value of number is: {}", number);

    //循环：loop while for
    //loop 无限循环，直到手动停止或跳出循环语句 break;
    let mut counter: i32 = 0;

    let result: i32 = loop {
        counter += 1;

        if counter == 10 {
            break counter * 2;
        }
    };
    // prints 20
    println!("{}",result);

    //while 循环
    let mut number: i32 = 3;

    while number != 0 {
        println!("{}!", number);

        number = number - 1;
    }

    println!("LIFTOFF!!!");

    //for循环
    //遍历数组很方便，不用担心像while数组越界的问题了。
    let a = [10, 20, 30, 40, 50];

    for element in a.iter() {
        println!("the value is: {}", element);
    }

    //也可以循环自定义
    //(1..4) Range标准库类型
    //rev()反转方法
    for number in (1..4).rev() {
        println!("{}!", number);
    }
    println!("LIFTOFF!!!");

}
